package com.example.combwx.mvp.presenter;

import android.util.Log;

import com.example.combwx.R;
import com.example.combwx.mvp.base.model.BaseEntity;
import com.example.combwx.mvp.base.presenter.BasePresenter;
import com.example.combwx.mvp.contract.UserContract;
import com.example.combwx.mvp.model.entity.UserItemEntity;
import com.example.combwx.mvp.model.entity.UserMenuEntity;
import com.umeng.socialize.media.Base;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class UserPresenter extends BasePresenter<UserContract.IUserModel, UserContract.IUserView> {

    @Inject
    public UserPresenter(UserContract.IUserModel iUserModel, UserContract.IUserView iUserView) {
        super(iUserModel, iUserView);
    }

    //初始化数据方法
    public void initData(){
        List<UserMenuEntity> menuse = new ArrayList<>();
        menuse.add(new UserMenuEntity(R.mipmap.res_icon7_274,"消息",null));
        menuse.add(new UserMenuEntity(R.mipmap.res_icon7_275,"收藏",null));
        menuse.add(new UserMenuEntity(R.mipmap.res_icon7_277,"评论",null));
        menuse.add(new UserMenuEntity(R.mipmap.res_icon7_276,"历史",null));
        menuse.add(new UserMenuEntity(R.mipmap.res_icon7_278,"关注",null));
        menuse.add(new UserMenuEntity(R.mipmap.res_icon7_279,"下载",null));
        menuse.add(new UserMenuEntity(R.mipmap.res_icon7_280,"公益",null));
        menuse.add(new UserMenuEntity(R.mipmap.res_icon7_281,"问政",null));
        v.refreshMenu(menuse);
        List<UserItemEntity>itemes = new ArrayList<>();
        itemes.add(new UserItemEntity("积分商城",null));
        itemes.add(new UserItemEntity("夜间模式",null));
        itemes.add(new UserItemEntity("意见反馈",null));
        itemes.add(new UserItemEntity("更多设置",null));
        v.refreshItemes(itemes);
    }

    public void selUser(int user_id,int code){
        Log.i("xrn", "selUser: "+111);
        Map<String,Object> map=new HashMap<>();
        map.put("user_id",user_id);
        map.put("code",code);
        m.requestUser(map).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);
    }

    @Override
    public void onNext(BaseEntity entity) {
        v.showUser(entity);
    }
}
